package com.bizzan.bitrade.listenConfig;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {
    
    @Autowired
    private RestTemplate restTemplate;
    
    // 使用 LoadBalanced RestTemplate
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
    
    @GetMapping("/order/{userId}")
    public String getUserOrder(@PathVariable String userId) {
        // 直接使用服务名进行调用，Nacos 会自动解析
        String userInfo = restTemplate.getForObject(
            "http://cloud-service/user/" + userId, String.class);
        return "Order for user: " + userInfo;
    }
}